import { Schema, ValidateFunction } from 'ajv';

export type SectionTarget =
  | 'context'
  | 'request_header'
  | 'request_query'
  | 'request_body'
  | 'response_header'
  | 'response_body';

interface ValidatorUnit {
  // jsonschema 规则
  json_schema?: Schema;
  // 经过编译后的jsonschema函数
  schema_compiled?: ValidateFunction<unknown>;
  // 预留自定义校验
  custom?: unknown;
  // 需要上报的字段
  report_raw_path?: string[];
}

export type Section = Partial<Record<SectionTarget, ValidatorUnit>>;

export type PresetSence = {
  preset_id: string;
  // 预设参数
  options?: unknown;
};
export interface Rule {
  api_path: string;
  // 规则信息
  info?: Record<string, string | number>;
  // 预设场景
  preset_sences?: PresetSence[];
  condition?: Section;
  validator?: Section;
}
export type RuleGroupItem = Rule & Record<string, string | number>;
